
package com.xiaoma.myaudience.biz.adapter;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.xiaoma.myaudience.R;
import com.xiaoma.myaudience.biz.model.ActivityDetailInfoModel;
import com.xiaoma.myaudience.biz.model.RankingListModel;
import com.xiaoma.myaudience.biz.task.AddEventTask;
import com.xiaoma.myaudience.biz.view.LoadingImageView;
import com.xiaoma.myaudience.util.PicUtils;
import com.xiaoma.myaudience.util.model.ModelUtils;

/**
 * 活动筛选Adapter
 * @author jpren
 *
 */
public class PersonalMypartActivityAdapter extends BaseAdapter implements OnClickListener{
    private List<Map<String, Object>> mList;	
    private Context mContext;
    private LayoutInflater mInflater;
    private String mSizeStr;
	private AddEventTask mAddEventTask;
	private String mErrorMsg;
    
    public PersonalMypartActivityAdapter(Context context, List<Map<String, Object>> list) {
        mList = list;
        mContext = context;
        mInflater = LayoutInflater.from(mContext);
        mSizeStr = PicUtils.composeSize((int) mContext.getResources().getDimension(
                R.dimen.list_item_img_height), (int) mContext.getResources().getDimension(
                R.dimen.list_item_img_width));
    }

    @Override
	public int getCount() {
		return mList.size();
	}

	@Override
	public Object getItem(int position) {
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.personal_mypartactivity_item, null);
			ViewHolder holder = new ViewHolder();
			holder.img = (LoadingImageView) convertView.findViewById(R.id.img);
			holder.title = ((TextView)convertView.findViewById(R.id.title));
			holder.startTime = ((TextView)convertView.findViewById(R.id.start_time));
			holder.location = ((TextView)convertView.findViewById(R.id.location));
			holder.limitNum = ((TextView)convertView.findViewById(R.id.limit_num));
			
            convertView.setTag(holder);
		}
		ViewHolder holder = (ViewHolder) convertView.getTag();
		final Map<String, Object> item = (Map<String, Object>) getItem(position);
		holder.img.setLoadingDrawable(ModelUtils.getStringValue(item, ActivityDetailInfoModel.PARAM_POSTER), mSizeStr);
		holder.title.setText(ModelUtils.getStringValue(item, RankingListModel.PARAM_TITLE));
		holder.startTime.setText("时间：" + ModelUtils.getStringValue(item, RankingListModel.PARAM_DEADTIME));
		holder.location.setText("位置：" + ModelUtils.getStringValue(item, RankingListModel.PARAM_LOCATION));
		holder.limitNum.setText(ModelUtils.getStringValue(item, RankingListModel.PARAM_MEMBERNUM) + "人参加 | " +
				ModelUtils.getStringValue(item, RankingListModel.PARAM_VIEWNUM) + "人点评");
		
		return convertView;
	}
	
	
	private class ViewHolder {
        LoadingImageView img;
        TextView title;
        TextView location;
        TextView startTime;
        TextView limitNum;
    }


	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		
	}
}